<!DOCTYPE html>
<html>

<head>
    <title>经济文明-登录</title>
    <meta charset="utf-8" />
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="shortcut icon" href="./static/img/favicon.ico" type="image/x-icon">

    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0" />
    <script src="/static/js/jquery.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("body").height(window.screen.height);
        });

        function chkIt(text) {
            var reg = new RegExp(/^[a-zA-Z0-9]+$/g);      //数字加密码
            if (!reg.test(text)) {
                alert("输入不规范");
                return false;
            }
            return true;
        }

  
        function next() {
            var username = $("#inputMail").val();
            var mail = username + "@newciviliz.me";
            if (chkIt(username)) {
                //验证码
                var existAccount = false;
                //检查账号是否存在
                $.get("https://box.newciviliz.me/admin/mail/users?format=json", (data, status) => {
                    var users = data[0].users;
                    var emails = [];

                    for (let index = 0; index < users.length; index++) {
                        const userinfo = users[index];
                        console.log(userinfo.email)
                        console.log(mail == userinfo.email)
                        if (mail == userinfo.email) {
                            existAccount = true;
                            //登录
                            var quit = false;
                            $.get("https://box.newciviliz.me/admin/mail/users/getpassword?email=" + username + "@newciviliz.me", (data, status) => {
                                    while (!quit) {
                                                var ret = window.prompt("请输入密码:", "");
                                                if (ret != null) {
                                                    if (ret.length < 8 || ret.length >= 30) {
                                                        alert("密码不符合规范")
                                                    } else {
                                                        console.log(data)
                                                        if (ret == data) {
                                                            quit = true;
                                                          window.location.href = "https://2020cn.cn";
                                                          window.localStorage.setItem("user", mail);

                                                        } else {
                                                            alert("密码输入错误")
                                                        }
                                                    }
                                                } else
                                                    quit = true;
                                      }
                                       
                                        });
                           

                            // window.location.href = "./home.html?user="+mail;
                            break;
                        }
                    }
                    if (!existAccount) {
                        alert("账号不存在，正在为您注册...")
                        $.post("https://box.newciviliz.me/admin/mail/users/add", encodeURI("email=" + username + "@newciviliz.me&password=12345678"), (data, status) => {
                            //if(status == "success")
                            //window.location.href = "./home.html?user="+mail;
                        })
                    }


                })
            }



        }
        
        function back() {
            window.location.href = "https://2020cn.cn";
        }
    </script>
    <style type="text/css">
        html {
            height: 100%;
        }

        body {
            height: 100%;
            text-align: center;
            background-image: url(./static/img/CircleBg-1CirCle.svg);
            background-size: 100% 100%;
            /* background-position-x: -50vw; */
            background-position-y: -50vh;
            background-repeat: no-repeat;
            overflow: hidden;
        }

        #loginBtn {
            border-color: #b1b2b5;
            position: absolute;
            right: 10%;
            bottom: 10%;
            border-radius: 50%;
            width: 13vw;
            height: 13vw;
            font-size: 3vw;
        }

        #backBtn {
            border-color: #b1b2b5;
            position: absolute;
            right: 10%;
            top: 10%;
            border-radius: 50%;
            width: 13vw;
            height: 13vw;
            font-size: 3vw;
        }

        #tipA {

            font-size: large;
            margin: 100px auto;
            /* 使容器水平边距自动相等 */
            line-height: 100px;
            /*设置line-height与rongqi的height相等*/
            text-align: center;
            /*设置文本水平居中*/
            overflow: hidden;
            /*防止内容超出容器或者产生自动换行*/

        }

        #inputMail {
            border-top: 0px;
            border-left: 0px;
            border-right: 0px;

            outline: none;
            text-align: right;
            padding: 13px 14px;
            width: 40%;
            font-size: large;
            font-weight: 700;
            font-family: "Microsoft soft";

        }

        #loginInputDiv {
            font-size: large;
            font-weight: 700;
            font-family: "Microsoft soft";
        }


        input::-webkit-input-placeholder,
        textarea::-webkit-input-placeholder {

            font-size: medium;
        }

        input:-moz-placeholder,
        textarea:-moz-placeholder {

            font-size: medium;
        }

        input::-moz-placeholder,
        textarea::-moz-placeholder {

            font-size: medium;
        }

        input:-ms-input-placeholder,
        textarea:-ms-input-placeholder {

            font-size: medium;
        }
    </style>
</head>

<body>
    <div id="tipA">
        <a
            href="https://design.penpot.app/#/view/64eb9b60-d2a2-11ec-ab9e-75f6b8214121?page-id=64eb9b61-d2a2-11ec-ab9e-75f6b8214121&section=interactions&index=0&share-id=1ed1d7e0-d4e9-11ec-ab9e-75f6b8214121">查看原型设计</a>
    </div>

    <div class="container" id="btnDiv">
        <button id="loginBtn" onclick="next()">开始</button>
        <button id="backBtn" onclick="back()">首页</button>

    </div>
    <div class="inputDiv" id="loginInputDiv">
        <input type="email" name="mail" id="inputMail" maxlength="10" placeholder="邮箱名(字母或数字)" />
        @newciviliz.me
        <br>
        未注册将自动注册新文明邮箱
    </div>
</body>

</html>